package com.itheima.dubbo.service;

import com.itheima.dubbo.User;
import com.itheima.dubbo.UserInterface;
import org.apache.dubbo.config.annotation.DubboService;
import org.apache.dubbo.rpc.RpcContext;

/**
 * @Description:
 * @Version: V1.0
 */
// dubbo 注册到注册中心
//@DubboService(timeout=300)  // 超时时间配置， 默认1s
//@DubboService(methods = {  //优先级最高
//        @Method(name = "hello",timeout = 9000),
//        @Method(name = "add",retries = 0)
//})
//@DubboService(retries=0)  //重试次数，默认是0,
// 幂等性：无论发送多少次请求，结果一致的
// 非冪等性：新增
// 互联网项目中不建议设置重试，设置重试次数不超过2次
//@DubboService(version = "1.0.1") // 版本号：灰度发布
@DubboService(loadbalance = "roundrobin", weight = 10) // 版本号：灰度发布
public class UserServiceImpl implements UserInterface {

    @Override
    public String hello(String username) {

        System.out.println("UserServiceImpl......");

        String jwt = RpcContext.getContext().getAttachment("jwt");
        System.out.println(jwt);
        try {
            Thread.sleep(2000L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        return "hello Dubbo username: "+username;
    }

    @Override
    public User findUser(User userVO) {
        User user = new User();
        user.setName(userVO.getName());
        return user;
    }
}
